/*
 * @Author: yao
 * @Date: 2024-10-31 10:23:32
 * @LastEditTime: 2024-11-15 18:45:05
 * @LastEditors: yao
 * @Description:
 * @FilePath: \jdev-web\vite.config.ts
 */
import { fileURLToPath, URL } from "node:url";
import { defineConfig, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue";
import vueJsx from "@vitejs/plugin-vue-jsx";
import vueDevTools from "vite-plugin-vue-devtools";
import Components from "unplugin-vue-components/vite";
import { PrimeVueResolver } from "@primevue/auto-import-resolver";

// https://vite.dev/config/
export default defineConfig(({ mode }) => {
  const env = loadEnv(mode, process.cwd());
  return {
    plugins: [
      vue(),
      vueJsx(),
      vueDevTools(),
      Components({
        resolvers: [PrimeVueResolver()],
      }),
    ],
    resolve: {
      alias: {
        "@": fileURLToPath(new URL("./src", import.meta.url)),
      },
    },
    server: {
      host: true,
      port: 10086,
      open: true,
      cors: true,
      proxy: {
        "/xddne-sm": {
          target: env.VITE_APP_API_URL,
          changeOrigin: true,
          rewrite: (path) => path.replace("^/xddne-sm", "/xddne-sm"),
        },
      },
    },
  };
});
